<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFilesTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('files', function (Blueprint $table) {
            $table->integer('id', true);
            $table->string('hash', 64)->unique()->comment('文件哈希串（唯一）');
            $table->string('name', 200)->comment('文件名');
            $table->string('path', 200)->comment('保存路径');
            $table->unsignedBigInteger('size')->comment('文件大小');
            $table->string('mime_type', 100)->comment('文件MimeType');
            $table->unsignedBigInteger('download_count')->default(0)->comment('下载次数');
            $table->unsignedBigInteger('ilk_type')->nullable()->index()->comment('文件关联对象类型');
            $table->unsignedBigInteger('ilk_id')->nullable()->index()->comment('文件关联对象ID');
            $table->string('group', 50)->nullable()->index()->comment('文件分组');
            $table->unsignedBigInteger('creator_user_id')->nullable()->index()->comment('上传者用户ID');
            $table->timestamps();
//            $table->comment('上传文件数据表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('files');
    }
};
